home *** CD-ROM | disk | FTP | other *** search
/ Aminet 15 / Aminet 15 - Nov 1996.iso / Aminet / dev / misc / libx11inc.lha / X11 / Xkw / LayoutP.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-23  |  5.4 KB  |  218 lines

  1. /*
  2.  * $XConsortium: LayoutP.h,v 1.2 92/01/22 18:03:08 keith Exp $
  3.  *
  4.  * Copyright 1991 Massachusetts Institute of Technology
  5.  *
  6.  * Permission to use, copy, modify, distribute, and sell this software and its
  7.  * documentation for any purpose is hereby granted without fee, provided that
  8.  * the above copyright notice appear in all copies and that both that
  9.  * copyright notice and this permission notice appear in supporting
  10.  * documentation, and that the name of M.I.T. not be used in advertising or
  11.  * publicity pertaining to distribution of the software without specific,
  12.  * written prior permission.  M.I.T. makes no representations about the
  13.  * suitability of this software for any purpose.  It is provided "as is"
  14.  * without express or implied warranty.
  15.  *
  16.  * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  17.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
  18.  * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  19.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  20.  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 
  21.  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  22.  *
  23.  * Author:  Keith Packard, MIT X Consortium
  24.  */
  25.  
  26. #ifndef _LayoutP_h
  27. #define _LayoutP_h
  28. #include    "Layout.h"
  29.  
  30.  
  31. #define GlueEqual(a,b)    ((a).order == (b).order && (a).value == (b).value)
  32.  
  33. #define AddGlue(r,a,b)    if (a.order == b.order) { \
  34.                 r.order = a.order; \
  35.                 r.value = a.value + b.value; \
  36.             } else { \
  37.                 if (a.order > b.order) \
  38.                 r = a; \
  39.                 else \
  40.                 r = b; \
  41.             }
  42.  
  43. #define MinGlue(r,a,b)    if (a.order == b.order) { \
  44.                 r.order = a.order; \
  45.                 if (a.value > b.value) \
  46.                 r.value = b.value; \
  47.                 else \
  48.                 r.value = a.value; \
  49.             } else { \
  50.                 if (a.order > b.order) \
  51.                 r = b; \
  52.                 else \
  53.                 r = a; \
  54.             }
  55.  
  56. #define SubGlue(r,a,b)    if (a.order == b.order) { \
  57.                 r.order = a.order; \
  58.                 r.value = a.value - b.value; \
  59.             } else { \
  60.                 if (a.order > b.order) \
  61.                 r = a; \
  62.                 else { \
  63.                 r.order = b.order; \
  64.                 r.value = -b.value; \
  65.                 } \
  66.             }
  67.  
  68. #define ZeroGlue(g)    ((g).value = 0, (g).order = 0, (g).expr = 0)
  69. #define IsZeroGlue(g)    ((g).value == 0)
  70.  
  71. #define QuarkToWidget(l,q)  XtNameToWidget((Widget) l, \
  72.                        (char *) XrmQuarkToString(q));
  73.                        
  74. typedef enum _BoxType { BoxBox, WidgetBox, GlueBox, VariableBox } BoxType;
  75.     
  76. typedef enum _LayoutDirection {
  77.     LayoutHorizontal = 0, LayoutVertical = 1
  78. } LayoutDirection;
  79.  
  80. typedef enum _Operator {
  81.     Plus, Minus, Times, Divide, Percent
  82. } Operator;
  83.  
  84. typedef enum _ExprType {
  85.     Constant,
  86.     Binary,
  87.     Unary,
  88.     Width,
  89.     Height,
  90.     Variable
  91. } ExprType;
  92.  
  93. typedef struct _Expr *ExprPtr;
  94.  
  95. typedef struct _Expr {
  96.     ExprType    type;
  97.     union {
  98.     double        constant;
  99.     struct {
  100.         Operator    op;
  101.         ExprPtr    left, right;
  102.     } binary;
  103.     struct {
  104.         Operator    op;
  105.         ExprPtr    down;
  106.     } unary;
  107.     XrmQuark    width;
  108.     XrmQuark    height;
  109.     XrmQuark    variable;
  110.     } u;
  111. } ExprRec;
  112.  
  113. typedef struct _Glue {
  114.     int        order;
  115.     double    value;
  116.     ExprPtr    expr;
  117. } GlueRec, *GluePtr;
  118.  
  119. typedef struct _BoxParams {
  120.     GlueRec stretch[2];
  121.     GlueRec shrink[2];
  122. } BoxParamsRec, *BoxParamsPtr;
  123.  
  124. typedef struct _Box *BoxPtr;
  125.  
  126. typedef BoxPtr    LayoutPtr;
  127.  
  128. typedef struct _Box {
  129.     BoxPtr        nextSibling;
  130.     BoxPtr        parent;
  131.     BoxParamsRec    params;
  132.     int            size[2];
  133.     int            natural[2];
  134.     BoxType        type;
  135.     union {
  136.     struct {
  137.         BoxPtr        firstChild;
  138.         LayoutDirection dir;
  139.     } box;
  140.     struct {
  141.         XrmQuark        quark;
  142.         Widget        widget;
  143.     } widget;
  144.     struct {
  145.         ExprPtr        expr;
  146.     } glue;
  147.     struct {
  148.         XrmQuark        quark;
  149.         ExprPtr        expr;
  150.     } variable;
  151.     } u;
  152. } BoxRec;
  153.  
  154. typedef struct _SubInfo {
  155.     int        naturalSize[2];
  156.     int        naturalBw;
  157. } SubInfoRec, *SubInfoPtr;
  158.  
  159. #define New(t) (t *) malloc(sizeof (t))
  160. #define Dispose(p)  free((char *) p)
  161. #define Some(t,n)   (t*) malloc(sizeof(t) * n)
  162. #define More(p,t,n) ((p)? (t *) realloc((char *) p, sizeof(t)*n):Some(t,n)
  163.  
  164. #define ForAllChildren(pw, childP) \
  165.   for ( (childP) = (pw)->composite.children ; \
  166.         (childP) < (pw)->composite.children + (pw)->composite.num_children ; \
  167.         (childP)++ ) if (!XtIsManaged(*childP)) ; else
  168.              
  169. /*********************************************************************
  170.  *
  171.  * Layout Widget Private Data
  172.  *
  173.  *********************************************************************/
  174.  
  175. /* New fields for the Layout widget class record */
  176.  
  177. typedef struct _LayoutClassPart {
  178.     int foo;            /* keep compiler happy. */
  179. } LayoutClassPart;
  180.  
  181. /* Full Class record declaration */
  182. typedef struct _LayoutClassRec {
  183.     CoreClassPart       core_class;
  184.     CompositeClassPart  composite_class;
  185.     ConstraintClassPart constraint_class;
  186.     LayoutClassPart     layout_class;
  187. } LayoutClassRec;
  188.  
  189. extern LayoutClassRec layoutClassRec;
  190.  
  191. typedef struct _LayoutConstraintsRec {
  192.     SubInfoRec    layout;
  193. } LayoutConstraintsRec, *LayoutConstraints;
  194.  
  195. #define SubInfo(w)  (&(((LayoutConstraints) (w)->core.constraints)->layout))
  196.  
  197. /* New Fields for the Layout widget record */
  198.  
  199. typedef struct {
  200.     /* resources */
  201.     LayoutPtr    layout;
  202.     Boolean    debug;
  203. } LayoutPart;
  204.  
  205. /**************************************************************************
  206.  *
  207.  * Full instance record declaration
  208.  *
  209.  **************************************************************************/
  210.  
  211. typedef struct _LayoutRec {
  212.     CorePart       core;
  213.     CompositePart  composite;
  214.     ConstraintPart constraint;
  215.     LayoutPart     layout;
  216. } LayoutRec;
  217. #endif
  218.